package com.chenyuan;

import org.testng.Assert;
import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITestResult;
import org.testng.annotations.Test;

/**
 * @ClassName: test3
 * @Author: 陈元
 * @Description:
 * @CreateDate: 2024/8/8 23:55
 * @Version: 1.0
 * @E-mail:1765065492@qq.com
 * @Link:https://github.com/1765065492
 */
public class test3 implements IHookable {
    @Override
    public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
        iHookCallBack.runTestMethod(iTestResult);
        if (iTestResult.getThrowable() != null) {
            System.out.println("Test method failed: " + iTestResult.getMethod().getMethodName());
            // 在这里可以根据需要记录日志或者执行其他操作
        }
    }
    @Test
    public void testInfo() {
        // 准备测试数据和对象
        Calculator calculator = new Calculator();

        // 执行被测试的方法
        int result = calculator.add(1, 3);

        try {
            // 验证结果是否符合预期
            Assert.assertEquals(result, 5, "Expected result should be 5");
        } catch (AssertionError e) {
            // 如果断言失败，将异常抛出到 TestNG 框架
            System.out.println("Assertion failed: " + e.getMessage());
        }
    }

    @Test
    public void anotherTest() {
        // 另一个测试用例
        System.out.println("Executing another test case.");
        // 添加其他测试逻辑
    }

}
